// pages/user/user-progress-feedback/index.js
const app = getApp()
import {
  request
} from "../../../utils/util";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    page: 1,
    size: 12,
    reachBottom: false
  },
  // 查看详情跳转详情页面
  goToDetail(e) {
    const id = e.currentTarget.dataset.id
    console.log(id)
    wx.navigateTo({
      url: '/pages/user/user-feedback-detail/index?id=' + id,
    })
  },
  onLoad() {
    this.loadData()
  },
  loadData(page) {
    request('/api/user/progress', app.globalData.token, 'get', {
      page: page || 1,
      size: this.data.size
    }).then(res => {
      if (res.code === 200) {
        let reachBottom = false
        if (page && res.data.length < this.data.size) {
          reachBottom = true
        }
        if(reachBottom) {
          wx.showToast({
            title: '已经到底了哦~',
            icon: 'none'
          })
        }
        if (this.data.reachBottom) return
        let list = this.data.list
        if (page) {
          list = [...list, ...res.data]
        } else {
          list = res.data
        }

        this.setData({
          list,
          page: page || 1,
          reachBottom
        })
      } else {
        wx.showToast({
          title: '请求失败，请重进该页面~',
          icon: 'none'
        })
      }
    })
  },


  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.loadData(this.data.page + 1)
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})